package org.opentcs.kcvehicle.communication.kc.udp.Service;

import org.opentcs.kcvehicle.communication.kc.udp.agv.param.AgvEvent;
import org.opentcs.kcvehicle.communication.kc.udp.agv.param.rsp.RcvEventPackage;

public class BaseCommand {

  public static String byteToHex(byte b) {
    // 将byte转换为无符号整数
    int unsignedByte = b & 0xFF;
    // 使用Integer.toHexString方法转换为十六进制字符串
    String hexString = Integer.toHexString(unsignedByte);
    // 如果字符串长度为1，需要在前面补0
    if (hexString.length() == 1) {
      return "0" + hexString;
    }
    return hexString;
  }

  public static void printInfo(AgvEvent agvEvent) {
    System.out.println("sended transationId : " + agvEvent.getTransationIdString());
    for (byte b : agvEvent.toBytes().getBody()) {
      System.out.print(byteToHex(b) + " ");
    }
  }

  public static void printInfo(RcvEventPackage rcv) {

    for (byte b : rcv.getDataBytes()) {
      System.out.print(byteToHex(b) + " ");
    }
  }

}
